package com.bw.lib_base.net

import com.blankj.utilcode.util.SPUtils
import com.zyj.retrofit.adapter.FlowCallAdapterFactory
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit


class RetrofitUtils {
    companion object{

        val client by lazy {
            OkHttpClient.Builder()
                .writeTimeout(10,TimeUnit.SECONDS)
                .readTimeout(10,TimeUnit.SECONDS)
                .connectTimeout(10,TimeUnit.SECONDS)
                .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .addInterceptor {

                    val token = SPUtils.getInstance().getString(Const.TOKEN,"aa")

                    val build = it.request().newBuilder()
                        .addHeader(Const.ACCESSID, "ac806d1f6a3949209be5a57ac84bf40d")
                        .addHeader(Const.TOKEN, token)
                        .build()

                    it.proceed(build)


                }
                .build()
        }


        val retrofit by lazy {
            Retrofit.Builder()
                .baseUrl(Const.URL)
                .client(client)
                .addCallAdapterFactory(FlowCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build()
        }
    }
}